import { _decorator, Component, Label, math, Node } from 'cc';
import { Card, CardExplain, CardName, CardPropertyType, CARDTYPE, CardTypeColor, CardTypeName, needCard } from '../../AshFramework/Datas/GameConstant';
import { CardController } from '../CardController';
import { EventManager, MyEvent } from '../../AshFramework/Managers/EventManager';
import { GameUtil } from '../GameUtil';
const { ccclass, property } = _decorator;


@ccclass('CardParticulars')
export class CardParticulars extends Component {
    @property(Node)
    CardNode: Node = null;

    @property(Label)
    NameLabel: Label = null;

    @property(Label)
    TypeLabel: Label = null;

    @property(Label)
    ExplainLabel: Label = null;

    @property(Label)
    PropertyLabel: Label = null;

    private _type: CARDTYPE = CARDTYPE.CARD_GRAY;
    private _number: number = 0;
    private _grade: number = 0;
    private _haveCard: number = 0;
    private _needCard: number = 0;
    private _amplificationType: string | null = null;//卡片增幅类型

    protected onLoad(): void {
        // this.show();
    }

    evolutionBtn() {
        if (this._haveCard >= this._needCard) {
            this.evolution();
        } else {
            GameUtil.showHint("卡牌碎片不够");
        }
    }

    evolution() {
        this._grade++;
        this._haveCard -= this._needCard;
        this._needCard = needCard[this._grade]
        EventManager.Scene.emit(MyEvent.CARD_EVOLUTION, this._type, this._number);
        this.PropertyLabel.string = this.CardNode.getComponent(CardController).getProperty();
    }

    show(card: Card) {
        this.CardNode.getComponent(CardController).initCard(card, false);
        this.NameLabel.string = CardName[card.type][card.number];
        this.TypeLabel.string = CardTypeName[card.type];
        this.TypeLabel.color = CardTypeColor[card.type];
        this.ExplainLabel.string = CardExplain[card.type][card.number];
        this.PropertyLabel.string = this.CardNode.getComponent(CardController).getProperty();

        this._type = card.type;
        this._number = card.number;
        this._grade = card.grade;
        this._haveCard = card.haveCount;
        this._needCard = needCard[card.grade];

    }

}


